<?php
/**
 * 全局函数
 * Created by PhpStorm.
 * User: cgx
 * Date: 2016/8/4
 * Time: 13:11
 */

function update_zhibo($source,$kw){
    $zhibo = M('zhibo');

    //判断爬取到的数据是否存在数据库，存在则更新记录，不存在则添加
    $res = $zhibo->where("zbid='$kw[zbid]' and source='$source'")->find();
    if($res){
        $id = $zhibo->where("zbid = '$kw[zbid]'")->save($kw);
        echo 'ok';
    }else{
        $id = $zhibo->data($kw)->add();
        echo 'ok';
    }
}

function befor_update($source){
    $zhibo = M('zhibo');
    $data['isOnlive']=0;
    $zhibo->where("source='$source'")->save($data);
}